import { InputQuestion, QuestionBase, TimeQuestion, SelectQuestion } from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { Api as ApiSystem } from '@/config/api/system';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'name',
        label: '文件名称',
        value: null
      }),
      new InputQuestion({
        key: 'code',
        label: '文件编码',
        value: null
      }),
      new TimeQuestion({
        label: '创建时间',
        state: {
          showTime: true,
          keySplit: ['createdTimeStart', 'createdTimeEnd'],
          format: 'YYYY-MM-DD HH:mm:ss',
          valueFormat: 'YYYY-MM-DD HH:mm:ss'
        }
      }),
      new TimeQuestion({
        label: '修改时间',
        state: {
          showTime: true,
          keySplit: ['modifiedTimeStart', 'modifiedTimeEnd'],
          format: 'YYYY-MM-DD HH:mm:ss',
          valueFormat: 'YYYY-MM-DD HH:mm:ss'
        }
      }),
      new SelectQuestion({
        key: 'creators',
        label: '创建人',
        value: [],
        state: {
          mode: 'multiple',
          url: ApiSystem.subjectListSimple,
          protType: 'post',
          nameKey: 'nickName',
          nameValue: 'id',
          showSearch: true,
          optionFilterProp: 'label'
        }
      })
    ];
    return questions;
  }
  getTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'num',
        value: '序号',
        type: 'index'
      }),
      new TextTable({
        key: 'name',
        value: '文件名称'
      }),
      new TextTable({
        key: 'code',
        value: '文件编码'
      }),
      new TextTable({
        key: 'version',
        value: '版本号'
      }),
      new TextTable({
        key: 'creatorName',
        value: '创建人'
      }),
      new TextTable({
        key: 'createdTime',
        value: '创建时间'
      }),
      new TextTable({
        key: 'modifierName',
        value: '修改人'
      }),
      new TextTable({
        key: 'modifiedTime',
        value: '修改时间',
        columns: {
          width: 150
        }
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        columns: {
          fixed: 'right',
          width: 150
        },
        handle: [
          {
            type: 'local',
            text: '预览',
            class: 'text-primary',
            params: [{ id: 'id' }],
            state: {}
          }
        ]
      })
    ];
    return tables;
  }
}

export default new HomeService();
